using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;

namespace WindowsFormsApplication1
{
    public partial class rptTKGVTheoPhai : DevExpress.XtraReports.UI.XtraReport
    {
        CalculatedField PT_TS = new CalculatedField();
        CalculatedField PT_ThS = new CalculatedField();
        CalculatedField PT_DH = new CalculatedField();
        CalculatedField PT_Sum_TS = new CalculatedField();
        CalculatedField PT_Sum_ThS = new CalculatedField();
        CalculatedField PT_Sum_DH = new CalculatedField();
        XRSummary Sum_SL_TS;
        XRSummary Sum_SL_ThS;
        XRSummary Sum_SL_DH;
        XRSummary Sum_Tong;
        int STT = 0;
        public rptTKGVTheoPhai()
        {
            InitializeComponent();
            CalculatedFields.AddRange(new CalculatedField[] { PT_TS, PT_ThS, PT_DH}); 
        }

        public void BindData(string tungay, string denngay)
        {
            colTungay.Text = tungay;
            colDenngay.Text = denngay;
            colPhai.DataBindings.Add("Text", DataSource, "Gioitinh");
            colSL_TS.DataBindings.Add("Text", DataSource, "TS");
            colSL_ThS.DataBindings.Add("Text", DataSource, "THS");
            colSL_DH.DataBindings.Add("Text", DataSource, "DH");
            ColTong.DataBindings.Add("Text", DataSource, "Tong");

            Sum_SL_TS = new XRSummary();
            colSum_SL_TS.DataBindings.AddRange(new XRBinding[] { new XRBinding("Text", null, "TS", "") });
            Sum_SL_TS.Running = SummaryRunning.Report;
            colSum_SL_TS.Summary = Sum_SL_TS;

            Sum_SL_ThS = new XRSummary();
            colSum_SL_ThS.DataBindings.AddRange(new XRBinding[] { new XRBinding("Text", null, "THS", "") });
            Sum_SL_ThS.Running = SummaryRunning.Report;
            colSum_SL_ThS.Summary = Sum_SL_ThS;

            Sum_SL_DH = new XRSummary();
            colSum_SL_DH.DataBindings.AddRange(new XRBinding[] { new XRBinding("Text", null, "DH", "") });
            Sum_SL_DH.Running = SummaryRunning.Report;
            colSum_SL_DH.Summary = Sum_SL_DH;

            Sum_Tong = new XRSummary();
            colSum_Tong.DataBindings.AddRange(new XRBinding[] { new XRBinding("Text", null, "Tong", "") });
            Sum_Tong.Running = SummaryRunning.Report;
            colSum_Tong.Summary = Sum_Tong;

            //Tinh % SL TS
            colPT_TS.DataBindings.AddRange(new XRBinding[] { new XRBinding("Text", null, "PT_TS", "{0:0.0%}") });
            PT_TS.Expression = "[TS] / [Tong]";
            PT_TS.FieldType = FieldType.Float;
            PT_TS.Name = "PT_TS";

            //Tinh % SL ThS
            colPT_ThS.DataBindings.AddRange(new XRBinding[] { new XRBinding("Text", null, "PT_ThS", "{0:0.0%}") });
            PT_ThS.Expression = "[THS] / [Tong]";
            PT_ThS.FieldType = FieldType.Float;
            PT_ThS.Name = "PT_ThS";

            //Tinh % SL DH
            colPT_DH.DataBindings.AddRange(new XRBinding[] { new XRBinding("Text", null, "PT_DH", "{0:0.0%}") });
            PT_DH.Expression = "[DH] / [Tong]";
            PT_DH.FieldType = FieldType.Float;
            PT_DH.Name = "PT_DH";
        }

        private void colSTT_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            STT++;
            colSTT.Text = STT.ToString();
        }

        private void colSum_PT_TS_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            float SL_TS = float.Parse(Sum_SL_TS.GetResult().ToString());
            float Tong = float.Parse(Sum_Tong.GetResult().ToString());
            colSum_PT_TS.Text = (SL_TS / Tong).ToString("0.0%"); 
        }

        private void colSum_PT_ThS_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            float SL_ThS = float.Parse(Sum_SL_ThS.GetResult().ToString());
            float Tong = float.Parse(Sum_Tong.GetResult().ToString());
            colSum_PT_ThS.Text = (SL_ThS / Tong).ToString("0.0%"); 
        }

        private void colSum_PT_DH_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            float SL_DH = float.Parse(Sum_SL_DH.GetResult().ToString());
            float Tong = float.Parse(Sum_Tong.GetResult().ToString());
            colSum_PT_DH.Text = (SL_DH / Tong).ToString("0.0%"); 
        }

    }
}
